package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.OrderBean;
import com.project.bean.ShopBean;
import com.project.mapper.IOrderMapper;
import com.project.mapper.IShopMapper;
import com.project.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Service
@Transactional
public class OrderServiceImpl implements IOrderService {
    @Autowired
    private IOrderMapper orderMapper;
    @Autowired
    private IShopMapper shopMapper;

    @Override
    public void add(OrderBean order, Integer userId) {
        order.setUserId(userId);
        //添加订单
        orderMapper.insert(order);
        //得到该用户的购物车信息
        QueryWrapper<ShopBean> qw = new QueryWrapper<>();
        qw.eq("fk_userId",userId);
        List<ShopBean> shopList = shopMapper.selectList(qw);

        //添加订单明细
        orderMapper.addOrderInfo(order.getId(),shopList);
        //清空该用户的购物信息
        shopMapper.delete(qw);
    }

    @Override
    public IPage<OrderBean> findByUser(Integer userId, int pageNO) {
        return null;
    }

    @Override
    public OrderBean findById(int orderId) {
        return null;
    }

    @Override
    public IPage<OrderBean> findByItems(String status, LocalDate startDate, LocalDate endDate, int pageNO) {
        return null;
    }

    @Override
    public void upateStatus(int orderId, String status) {

    }

    @Override
    public List<OrderBean> findBySend() {
        return null;
    }
}
